package pro.softzhang.algo.lc1200;

import pro.softzhang.algo.common.ListNode;

/**
 *
 */
public class LC1290_ConvertBinaryNumberInALinkedListToInteger {
    public static void main(String[] args) {
        ListNode head = new ListNode(1, new ListNode(0, new ListNode(1, null)));
        int v = new Solution().getDecimalValue(head);
        System.out.println(v);
    }

    static class Solution {
        public int getDecimalValue(ListNode head) {
            if (head == null)
                return 0;

            int v = 0;
            while (head != null) {
                v = (v << 1) + head.val;
                head = head.next;
            }

            return v;
        }
    }
}
